package com.venusj.ipersistence.sqlSession;

import com.venusj.ipersistence.config.XmlConfigBuilder;
import com.venusj.ipersistence.pojo.Configuration;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

/**
 * @author zhangjh
 * @date 2020/10/15
 * @desc
 */
public class SqlSessionFactoryBuilder {

    public SqlSessionFactory build(InputStream inputStream) throws PropertyVetoException, DocumentException {
        // 使用dom4j解析配置文件，将解析出来的内容封装到容器对象中
        XmlConfigBuilder xmlConfigBuilder = new XmlConfigBuilder();
        Configuration configuration = xmlConfigBuilder.parseConfig(inputStream);


        // 创建SqlSessionFactory对象；生产sqlSession（会话对象），使用工厂模式
        DefaultSqlSessionFactory defaultSqlSessionFactory = new DefaultSqlSessionFactory(configuration);


        return defaultSqlSessionFactory;
    }
}
